package io.mft.runtime.function.process;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.mft.api.domain.Api;
import io.mft.commons.exception.MFTException;
import io.mft.commons.function.ExecuteReturn;
import io.mft.flow.core.FlowExecutor;
import io.mft.flow.data.ChainContext;
import io.mft.flow.data.ExecutableRequest;
import io.mft.flow.data.ExecutableResponse;
import io.mft.runtime.MFTApiExecutor;
import io.mft.runtime.function.ApiContext;
import io.mft.runtime.function.FunctionExecutor;
/**
 * 原子接口执行入口
 * @说明：TODO
 * @类型名称：ApiFunctionExecutor
 * @创建者: 胡常建  
 * @创建时间: 2021年7月5日 上午11:28:58
 * @修改者: 胡常建  
 * @修改时间: 2021年7月5日 上午11:28:58
 */
public class ApiFunctionExecutor extends FunctionExecutor {
	static Logger logger=LoggerFactory.getLogger(ApiFunctionExecutor.class);
	@Override
	public ExecuteReturn doExecute(ApiContext context) {
		try {
			FlowExecutor executor = MFTApiExecutor.getInstance().getRuntimeResource().getFlowExecutor();
			Api api=context.getApiExecutorObject().getApi();
			ExecutableRequest request=new ExecutableRequest(context.getRequest().getRequestValue());
			ExecutableResponse response=new ExecutableResponse(context.getResponse());
			ChainContext chainContext=new ChainContext(api.getKey(),request,request, response,api.getKey());
			ExecuteReturn executeReturn=executor.execute(api.getKey(), chainContext);	
			return executeReturn;
		} catch (MFTException e) {
			throw e;
		}catch (Exception e) {
			throw new MFTException(e);
		}finally {
			try {
			} catch (Exception e2) {
				logger.error("",e2);
			}
			
		}
	}
	
}
